package tests;

import java.io.File;

import org.apache.log4j.Logger;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.studerb.model.NewsGroup;
import com.studerb.service.interfaces.IFileService;
import com.studerb.service.interfaces.INewsGroupService;

public class TestFileService {
	private static Logger logger = Logger.getLogger("TESTS");
	private static ClassPathXmlApplicationContext springAppContext;
	private static IFileService fileService;
	private static INewsGroupService newsGroupService;
	private static String groupName = "a2000.erotica.binaries";


	public static void main(String args[]) {
		NewsGroup newsGroup;
		com.jidesoft.utils.Lm.verifyLicense("Bill Studer", "Gnusbin", "GUPxWo:0hpUtR3u94.K90:R7sPr.VCv2");
		System.out.println("Starting");
		try {
			setUpSpring();
			newsGroup = newsGroupService.getByGroupName(groupName);
			System.err.println("Got newsGroup: " + newsGroup.toString());
			File downloadDir = fileService.getDownloadDirectory(newsGroup);
			System.err.println("Got downloaddir: " + downloadDir.getAbsolutePath());
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			springAppContext.close();
		}

		System.exit(0);
	}
	
	private static void setUpSpring() {
		logger.debug("Starting Spring Application Context");
		springAppContext = new ClassPathXmlApplicationContext(new String[] { "testContext.xml" });
		newsGroupService = (INewsGroupService) springAppContext.getBean("newsGroupService");
		fileService = (IFileService) springAppContext.getBean("fileService");
		springAppContext.registerShutdownHook();
	}
}